package com.java.module.cms.controller.admin;

import java.util.List;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.common.utils.poi.ExcelUtil;
import com.java.module.cms.domain.Help;
import com.java.module.cms.service.IHelpService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础：帮助中心Controller
 *
 * @author Administrator
 * @date 2021-04-01
 */
@RestController("AdminHelpController")
@RequestMapping("/cms/help")
public class HelpController {

    @Autowired
    private IHelpService helpService;

    /**
     * 查询基础：帮助中心列表
     */
    @PreAuthorize("@ss.hasPermi('cms:help:list')")
    @GetMapping("/list")
    public TableDataInfo list(Help help) {
        WebKit.startPage();
        List<Help> list = helpService.selectHelpList(help);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出基础：帮助中心列表
     */
    @PreAuthorize("@ss.hasPermi('cms:help:export')")
    @Log(title = "基础：帮助中心", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Help help) {
        List<Help> list = helpService.selectHelpList(help);
        ExcelUtil<Help> util = new ExcelUtil<Help>(Help.class);
        return util.exportExcel(list, "help");
    }

    /**
     * 获取基础：帮助中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:help:query')")
    @GetMapping(value = "/{hid}")
    public AjaxResult getInfo(@PathVariable("hid") Long hid) {
        return AjaxResult.success(helpService.selectHelpById(hid));
    }

    /**
     * 新增基础：帮助中心
     */
    @PreAuthorize("@ss.hasPermi('cms:help:add')")
    @Log(title = "基础：帮助中心", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Help help) {
        return WebKit.toAjax(helpService.insertHelp(help));
    }

    /**
     * 修改基础：帮助中心
     */
    @PreAuthorize("@ss.hasPermi('cms:help:edit')")
    @Log(title = "基础：帮助中心", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Help help) {
        return WebKit.toAjax(helpService.updateHelp(help));
    }

    /**
     * 删除基础：帮助中心
     */
    @PreAuthorize("@ss.hasPermi('cms:help:remove')")
    @Log(title = "基础：帮助中心", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{hids}")
    public AjaxResult remove(@PathVariable Long[] hids) {
        return WebKit.toAjax(helpService.deleteHelpByIds(hids));
    }

}